//
//  YTEditCommentView.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/24.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTEditCommentView.h"
@interface YTEditCommentView ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UILabel *placeHolderLabel;

@end
@implementation YTEditCommentView

+ (instancetype)commentViewWithFrame:(CGRect)frame
{
    UINib *nib = [UINib nibWithNibName:@"YTEditCommentView" bundle:nil];
    YTEditCommentView *view = [nib instantiateWithOwner:nil options:nil][0];
    view.frame = frame;
    view.backgroundColor = UIColor.whiteColor;
    return view;
}

// 关闭按钮
- (IBAction)closeButton:(UIButton *)sender
{
    NSAssert(self.closeButtonClick != nil, @"closeButtonClick不能为nil");

    self.closeButtonClick(false);
}

// 发送评论按钮
- (IBAction)postCommentBtnClick:(UIButton *)sender
{
    if (!self.textView.hasText) {
        return;
    }
    
    sender.enabled = false;
    [YTNetworkManager.shareManager postCommentWithPostID:self.ID
                                                 content:self.textView.text
                                              completion:^(BOOL isSucc, NSString *statusInfo)
    {
        if (!isSucc) {
            [self.superview showTipWithTipStr:statusInfo];
            sender.enabled = YES;
            return ;
        }
        sender.enabled = YES;
        NSString *tip = statusInfo ? [NSString stringWithFormat:@"评论成功 +%@ 算力",statusInfo] : @"评论成功";
        [self showAwardWithTipStr:tip];
        
        isSucc ? self.closeButtonClick(YES) : nil;;
        
    }];
}

#pragma mark: - UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView
{
    self.placeHolderLabel.hidden = textView.hasText;
}
- (void)showKeybord
{
    [self.textView becomeFirstResponder];
}

- (void)awakeFromNib
{
    [super awakeFromNib];

    // setTextView
    self.textView.layer.masksToBounds = YES;
    self.textView.layer.cornerRadius = 5;
    self.textView.layer.borderWidth = 1;
    self.textView.layer.borderColor = [kMainColor CGColor];
    self.textView.delegate = self;
    
    // setshadow
    self.layer.masksToBounds = false;
    self.layer.shadowColor = UIColor.lightGrayColor.CGColor;
    self.layer.shadowOffset = CGSizeMake(0, 1);
    self.layer.shadowOpacity = 0.8;
    self.layer.shadowRadius = 5;
    
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    
    
}
@end
